/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.web.controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.cx1.web.utils.SessionUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.view.RedirectView;


/**
 *
 * @author ECH
 */
public class LogoutController extends AbstractController {
    
    public LogoutController() {
    }
    
    protected ModelAndView handleRequestInternal( HttpServletRequest request,
                                                  HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView();
        Map map = new HashMap();
        
        String userID = SessionUtils.getUserID(request.getSession());
        if (StringUtils.isEmpty(userID)) {
            mav.setView( new RedirectView("login.htm") );
            return mav;
        }
        
        int action = StringUtils.isEmpty( request.getParameter("a") ) ? 0 : Integer.parseInt(request.getParameter("a"));
        
        switch (action) {
            default: {
                SessionUtils.removeUserID(request.getSession());
                mav.setView(new RedirectView("login.htm"));
                break;
            }
        }        
        mav.addObject("model", map);
        return mav;
    }
}
